package com.bangdream.michelia.view.activity.exam;

import android.content.SyncStatusObserver;

import com.bangdream.michelia.entity.exam.AnswerBean;
import com.bangdream.michelia.utils.L;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @date on 2018/8/20 0:38
 * @email 909732184@qq.com
 * 考试的答题信息
 */
public class ExamHelper {
    //标记的集合
    private Set<Integer> sign = new HashSet<>();
    //1已答 未答
    private List<Boolean> isAnswerBegin = new ArrayList<>();
    //private LinkedHashMap<Integer,List<AnswerBean>> answerBeans = new LinkedHashMap<>();
    //public void putAnswerBean(int )
    //保存本次考试所有提交过的答案 在计时器到时间调用交卷时
    // 可能当前页的考题信息还没加载完毕则取最后一题的数据按交卷重新提交一次
    private LinkedHashSet<AnswerBean> answerBeans = new LinkedHashSet<>();
    private static ExamHelper instance;

    private ExamHelper() {

    }

    public void putAnswer(AnswerBean data){
        answerBeans.add(data);
        L.d(data.toString());
        L.d(answerBeans.size()+"");
    }

    public LinkedHashSet<AnswerBean> getAnswerBeans() {
        return answerBeans;
    }

    public static ExamHelper getInstance() {
        synchronized (ExamHelper.class) {
            if(instance==null){
                instance = new ExamHelper();
            }
        }
        return instance;
    }

    public List<Boolean> getIsAnswerBegin() {
        return isAnswerBegin;
    }

    public void setIsAnswerBegin(List<Boolean> isAnswerBegin) {
        this.isAnswerBegin = isAnswerBegin;
    }

    public Set<Integer> getSign() {
        return sign;
    }

    public void setSign(Set<Integer> sign) {
        this.sign = sign;
    }

    //标记或者取消标记
    public void SignSetSelect(int position)
    {
        if (sign.contains(position)) {
            sign.remove(position);
        } else {
            sign.add(position);
        }
    }
    //清空
    public void clean(){
        sign.clear();
        isAnswerBegin.clear();
        answerBeans.clear();
        instance = null;
    }
}
